package main

import (
	pb "learngo/user-service/proto/user"
	"context"
	"log"
	"github.com/micro/go-micro"
	_"github.com/micro/go-plugins/broker/googlepubsub"
	"fmt"
)

const topic = "user.created"

type Subscriber struct{}

func (sub *Subscriber)Process(ctx context.Context, user *pb.User) error  {
	log.Println("Picked up a new message")
	log.Println("Sending email to:", user.Name)

	return nil
}


func main() {
	srv := micro.NewService(
		micro.Name("go.micro.srv.email"),
		micro.Version("latest"),
	)

	srv.Init()

	micro.RegisterSubscriber(topic,srv.Server(),new(Subscriber))

	// Run the server
	if err := srv.Run(); err != nil {
		log.Fatalf("srv run error: %v\n", err)
	}


}


func senEmail(user *pb.User) {
	fmt.Println("----###----: send eamil to user" + user.Name)
}
